var url = '', jsonData = '';
$(function(){
	
	loadEmployeeData();
 
});


function loadEmployeeData(){
	/**
	 * 当前工资
	 */
	loadTalentWagesDetails();
	/**
	 * 调薪记录
	 */
	loadTalentWage();
	
	/**
	 * 薪酬成本
	 */
	loadSalary();
	/**
	 * 社保福利成本
	 */
	loadSocialSecurityBenefits();
}


function commonAjax(){
	var result = '';
	$.ajax({
		type: 'GET',
		data: jsonData,
	    url: url,
	    async: false,
	    dataType:"json",
	    success: function(data){
	    	result = data;
	    },
	    error: function(){
	    }
	});
	return result;
}

function loadTalentWagesDetails() {
	url = ctx + '/employeeDetailsController/talentWagesDetails';
	var jobNumber = $("#job_numberInput").val();
	jsonData = {jobNumber:jobNumber};
	var  returnData= commonAjax();
	var returnHtml = initTalentWagesDetails(returnData);
	
	$('#current_salary').html(returnHtml);
}

function loadTalentWage() {
	url = ctx + '/employeeDetailsController/talentWage';

	var jobNumber = $("#job_numberInput").val();
	
	jsonData = {jobNumber:jobNumber};
	var  returnData= commonAjax();
	var returnHtml = initTalentWage(returnData);
	
	$('#SalaryIncreaseExperience_tbody').html(returnHtml);
}

function loadSalary() {
	url = ctx + '/employeeDetailsController/payrollCost';
	var jobNumber = $("#job_numberInput").val();
	var startTime = $("#startSalary").val();
	var endTime = $("#endSalary").val();
	
if (startTime.length==0||endTime.length==0||startTime==endTime) {
		
		var date = new Date();
		var year = date.getFullYear();
		var month = date.getMonth()+1;
		var day = date.getDate();
		
		var startYear = year-1;
		
		startTime = startYear+"-"+month;
		endTime = year+"-"+month;
		
	}
	
	$('#startSalary').val(startTime);
	$('#endSalary').val(endTime);
	
	jsonData = {jobNumber:jobNumber,startTime:startTime,endTime:endTime};
	var  returnData= commonAjax();
	initLineDataChart(returnData.title,returnData.data,returnData.dates,returnData.name1,document.getElementById('salaryMain'));
	
}

function loadSocialSecurityBenefits() {
	url = ctx + '/employeeDetailsController/socialSecurityWelfareCost';
	var jobNumber = $("#job_numberInput").val();
	var startTime = $("#startSalary").val();
	var endTime = $("#endSalary").val();
	
if (startTime.length==0||endTime.length==0||startTime==endTime) {
		
		var date = new Date();
		var year = date.getFullYear();
		var month = date.getMonth()+1;
		var day = date.getDate();
		
		var startYear = year-1;
		
		startTime = startYear+"-"+month;
		endTime = year+"-"+month;
		
	}
	
	$('#startSalary').val(startTime);
	$('#endSalary').val(endTime);
	jsonData = {jobNumber:jobNumber,startTime:startTime,endTime:endTime};
	var  returnData= commonAjax();
	
	initLineDataChart(returnData.title,returnData.data,returnData.dates,returnData.name1,document.getElementById('socialSecurityBenefitsMain'));
	
}


function initTalentWagesDetails(data) {
	var returnHtml = '';
	
	if (data.length == 0)
		returnHtml = '<tr><td colspan="5">暂无数据</td></tr>';
	else
		returnHtml += data[0].basic_wage;
		/*$.each(data, function(index, item) {
			
			returnHtml += item.basic_wage;
			
		});*/
	
	
	return returnHtml;
}
 
function initTalentWage(data) {
	var returnHtml = '';
	
	if (data.length == 0)
		returnHtml = '<tr><td colspan="5">暂无数据</td></tr>';
	else
		
		$.each(data, function(index, item) {
			if (item.note==null) {
				item.note = " ";
			}
			returnHtml += "<tr>"
				+ "<td>" +item.adjust_date+ "</td>"
				+ "<td>"+item.adjusted_basic_wage+"</td>" 
				+ "<td>" + item.adjusted_performance+ "</td>" 
				+ "<td>"+ item.adjusted_bonus + "</td>" 
				+ "<td>"+ item.adjusted_t_level + "</td>"
				+ "<td>"+ item.adjusted_social_security_welfare_cost + "</td>"
				+ "<td>"+ item.adjusted_human_resource_cost + "</td>"
				+ "<td>"+ item.note + "</td></tr>";
			
		});
	
	
	return returnHtml;
}

